package Dao.Admin.Imp;

import Dao.Admin.AdminCountDao;
import Util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class AdminCountDaoImp implements AdminCountDao {
    private PreparedStatement ps = null;
    private ResultSet rs = null;

    /**查询学生总数*/
    public Integer adminStuCount(Connection conn){
        int result = 0;
        try {
            String sql = " select count(sno) from stu_Info ";
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            if (rs.next()){
                result = rs.getInt(1);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.closeMySQLResource(ps, rs);
        }
        return result;
    }
    /**查询已选题学生数*/
    public Integer adminStuTitleCount(Connection conn){
        int result = 0;
        try {
            String sql = " select count(sname) from title ";
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            if (rs.next()){
                result = rs.getInt(1);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.closeMySQLResource(ps, rs);
        }
        return result;
    }


    /**任务书学生总数*/
    public Integer assignCount(Connection conn){
        int result = 0;
        try {
            String sql = " select count(sno) from task ";
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            if (rs.next()){
                result = rs.getInt(1);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.closeMySQLResource(ps, rs);
        }
        return result;
    }
    /**任务书学生完成数*/
    public Integer assignPassCount(Connection conn){
        int result = 0;
        try {
            String sql = " select count(sno) from task where is_pass = ? ";
            ps = conn.prepareStatement(sql);
            ps.setString(1,"通过");
            rs = ps.executeQuery();
            if (rs.next()){
                result = rs.getInt(1);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.closeMySQLResource(ps, rs);
        }
        return result;
    }


    /**开题报告学生总数*/
    public Integer reportCount(Connection conn){
        int result = 0;
        try {
            String sql = " select count(sno) from report ";
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            if (rs.next()){
                result = rs.getInt(1);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.closeMySQLResource(ps, rs);
        }
        return result;
    }
    /**开题报告学生完成数*/
    public Integer reportPassCount(Connection conn){
        int result = 0;
        try {
            String sql = " select count(sno) from report where is_pass = ? ";
            ps = conn.prepareStatement(sql);
            ps.setString(1,"通过");
            rs = ps.executeQuery();
            if (rs.next()){
                result = rs.getInt(1);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.closeMySQLResource(ps, rs);
        }
        return result;
    }


    /**中期检查学生总数*/
    public Integer mediumCount(Connection conn){
        int result = 0;
        try {
            String sql = " select count(sno) from medium ";
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            if (rs.next()){
                result = rs.getInt(1);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.closeMySQLResource(ps, rs);
        }
        return result;
    }
    /**中期检查学生完成数*/
    public Integer mediumPassCount(Connection conn){
        int result = 0;
        try {
            String sql = " select count(sno) from medium where is_pass = ? ";
            ps = conn.prepareStatement(sql);
            ps.setString(1,"通过");
            rs = ps.executeQuery();
            if (rs.next()){
                result = rs.getInt(1);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.closeMySQLResource(ps, rs);
        }
        return result;
    }


    /**论文初稿学生总数*/
    public Integer firstCount(Connection conn){
        int result = 0;
        try {
            String sql = " select count(sno) from stage_check where phase = '初稿'  ";
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            if (rs.next()){
                result = rs.getInt(1);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.closeMySQLResource(ps, rs);
        }
        return result;
    }
    /**论文初稿学生完成数*/
    public Integer firstPassCount(Connection conn){
        int result = 0;
        try {
            String sql = " select count(sno) from stage_check where phase = '初稿' and is_pass = ? ";
            ps = conn.prepareStatement(sql);
            ps.setString(1,"通过");
            rs = ps.executeQuery();
            if (rs.next()){
                result = rs.getInt(1);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.closeMySQLResource(ps, rs);
        }
        return result;
    }


    /**定稿学生总数*/
    public Integer finalizeCount(Connection conn){
        int result = 0;
        try {
            String sql = " select count(sno) from stage_check where phase = '定稿' ";
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            if (rs.next()){
                result = rs.getInt(1);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.closeMySQLResource(ps, rs);
        }
        return result;
    }
    /**定稿学生完成数*/
    public Integer finalizePassCount(Connection conn){
        int result = 0;
        try {
            String sql = " select count(sno) from stage_check where phase = '定稿' and is_pass = ? ";
            ps = conn.prepareStatement(sql);
            ps.setString(1,"通过");
            rs = ps.executeQuery();
            if (rs.next()){
                result = rs.getInt(1);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.closeMySQLResource(ps, rs);
        }
        return result;
    }


    /**终稿学生总数*/
    public Integer finalCount(Connection conn){
        int result = 0;
        try {
            String sql = " select count(sno) from stage_check where phase = '终稿' ";
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            if (rs.next()){
                result = rs.getInt(1);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.closeMySQLResource(ps, rs);
        }
        return result;
    }
    /**终稿学生完成数*/
    public Integer finalPassCount(Connection conn){
        int result = 0;
        try {
            String sql = " select count(sno) from stage_check where phase = '终稿' and is_pass = ? ";
            ps = conn.prepareStatement(sql);
            ps.setString(1,"通过");
            rs = ps.executeQuery();
            if (rs.next()){
                result = rs.getInt(1);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.closeMySQLResource(ps, rs);
        }
        return result;
    }
}
